package com.cynteka.cyfoman.core.config;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;

@XmlRootElement
public class ParamMD {

    private String id;

    private String name;

    private ParamType paramType;

    private List<String> possibleValues;

    private String possibleValuesSQL;

    private String defaultValue;

    private boolean readOnly = false;

    private boolean required;

    private int maxLength;

    private CollectionMD collection;

    private String group;

    @XmlElement
    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    public ParamMD() {

    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ParamMD paramMD = (ParamMD) o;

        if (maxLength != paramMD.maxLength) return false;
        if (readOnly != paramMD.readOnly) return false;
        if (required != paramMD.required) return false;
        if (collection != null ? !collection.equals(paramMD.collection) : paramMD.collection != null) return false;
        if (defaultValue != null ? !defaultValue.equals(paramMD.defaultValue) : paramMD.defaultValue != null)
            return false;
        if (id != null ? !id.equals(paramMD.id) : paramMD.id != null) return false;
        if (name != null ? !name.equals(paramMD.name) : paramMD.name != null) return false;
        if (paramType != paramMD.paramType) return false;
        if (possibleValues != null ? !possibleValues.equals(paramMD.possibleValues) : paramMD.possibleValues != null)
            return false;
        if (possibleValuesSQL != null ? !possibleValuesSQL.equals(paramMD.possibleValuesSQL) : paramMD.possibleValuesSQL != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (paramType != null ? paramType.hashCode() : 0);
        result = 31 * result + (possibleValues != null ? possibleValues.hashCode() : 0);
        result = 31 * result + (possibleValuesSQL != null ? possibleValuesSQL.hashCode() : 0);
        result = 31 * result + (defaultValue != null ? defaultValue.hashCode() : 0);
        result = 31 * result + (readOnly ? 1 : 0);
        result = 31 * result + (required ? 1 : 0);
        result = 31 * result + maxLength;
        result = 31 * result + (collection != null ? collection.hashCode() : 0);
        return result;
    }

    @XmlElement
    public CollectionMD getCollection() {

        return collection;
    }

    public void setCollection(CollectionMD collection) {
        this.collection = collection;
    }

    @XmlElement
    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    @XmlElement
    public String getPossibleValuesSQL() {
        return possibleValuesSQL;
    }

    public void setPossibleValuesSQL(String possibleValuesSQL) {
        this.possibleValuesSQL = possibleValuesSQL;
    }

    public ParamMD(String name, ParamType paramType) {
        super();
        this.name = name;
        this.paramType = paramType;
    }

    public ParamMD(String name, ParamType paramType, List<String> possibleValues) {
        this(name, paramType);
        this.possibleValues = possibleValues;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlElement
    public String getName() {
        return name;
    }

    public void setParamType(ParamType paramType) {
        this.paramType = paramType;
    }


    @XmlElement
    public List<String> getPossibleValues() {
        return possibleValues;
    }

    public void setPossibleValues(List<String> possibleValues) {
        this.possibleValues = possibleValues;
    }

    @XmlElement
    public ParamType getParamType() {
        return paramType;
    }

    @XmlElement
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @XmlElement
    public boolean isReadOnly() {
        return readOnly;
    }

    public void setReadOnly(boolean readOnly) {
        this.readOnly = readOnly;
    }

    @XmlElement
    public boolean isRequired() {
        return required;
    }

    public void setRequired(boolean required) {
        this.required = required;
    }

    @XmlElement
    public int getMaxLength() {
        return maxLength;
    }

    public void setMaxLength(int maxLength) {
        this.maxLength = maxLength;
    }

    @Override
    public String toString() {
        return "ParamMD{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", paramType=" + paramType +
                ", possibleValues=" + possibleValues +
                ", possibleValuesSQL='" + possibleValuesSQL + '\'' +
                ", defaultValue='" + defaultValue + '\'' +
                ", readOnly=" + readOnly +
                ", required=" + required +
                ", maxLength=" + maxLength +
                ", collection=" + collection +
                '}';
    }

}
